package dao

import (
	"errors"
	"gin-ranking/api/lock/entity"
	"gin-ranking/common/result"
	"gin-ranking/pkg/db"
	"gorm.io/gorm"
)

type DeviceLockInfoDao struct{}

// QueryById 根据主键查询
func (DeviceLockInfoDao) QueryById(id string) entity.DeviceLockInfoEntity {
	var dataResult entity.DeviceLockInfoEntity
	//err := db.DB.Model(entity.DeviceLockInfoEntity{}).Select("*").Where("lock_id = ?", id).First(&dataResult).Error
	err := db.DB.Where("lock_id = ?", id).First(&dataResult).Error
	if err != nil && !errors.Is(err, gorm.ErrRecordNotFound) {
		panic(result.FailMag(err.Error()))
	}
	return dataResult
}
